package cn.tedu.spring.config;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class ConnectionPoolConfiguration {
    /**javax.sql.DataSource 数据源接口对象，
     * 所有连接池都会默认实现此接口规范*/
    @Bean
    public javax.sql.DataSource hikariDataSource(JdbcProperties jdbcProperties){
        //1.构建Hiari配置对象
        HikariConfig hikariConfig=new HikariConfig();
        hikariConfig.setDriverClassName(jdbcProperties.getDriver());
        hikariConfig.setJdbcUrl(jdbcProperties.getUrl());
        hikariConfig.setUsername(jdbcProperties.getUsername());
        hikariConfig.setPassword(jdbcProperties.getPassword());
        //2.基于Hikari配置对象构建HikariDataSource对象
        return new HikariDataSource(hikariConfig);
    };



}
